home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / a_convolute.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-20  |  5.2 KB  |  305 lines

  1. ;    VirtualDub - Video processing and capture application
  2. ;    Copyright (C) 1998-2001 Avery Lee
  3. ;
  4. ;    This program is free software; you can redistribute it and/or modify
  5. ;    it under the terms of the GNU General Public License as published by
  6. ;    the Free Software Foundation; either version 2 of the License, or
  7. ;    (at your option) any later version.
  8. ;
  9. ;    This program is distributed in the hope that it will be useful,
  10. ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;    GNU General Public License for more details.
  13. ;
  14. ;    You should have received a copy of the GNU General Public License
  15. ;    along with this program; if not, write to the Free Software
  16. ;    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     .586
  19.     .mmx
  20.     .model    flat
  21.     .code
  22.  
  23.     extern _MMX_enabled : byte
  24.  
  25.     public    _asm_convolute_run
  26.     public    _asm_dynamic_convolute_run
  27.  
  28. ;asm_convolute_run(
  29. ;    [esp+ 4] void *dst,
  30. ;    [esp+ 8] void *src,
  31. ;    [esp+12] ulong width,
  32. ;    [esp+16] ulong height,
  33. ;    [esp+20] ulong srcstride,
  34. ;    [esp+24] ulong dststride,
  35. ;    [esp+28] long *convol_matrix);
  36.  
  37. _asm_convolute_run:
  38. ;    test    _MMX_enabled, 1
  39. ;    jnz    _asm_average_run_MMX
  40.  
  41.     push    ebp
  42.     push    edi
  43.     push    esi
  44.     push    edx
  45.     push    ecx
  46.     push    ebx
  47.     push    eax
  48.  
  49.     sub    esp,40
  50.  
  51.     cld
  52.     mov    esi,[esp+28+28+40]
  53.     mov    edi,esp
  54.     mov    ecx,10
  55.     rep    movsd
  56.  
  57.     mov    esi,[esp+ 8+28+40]
  58.     mov    edi,[esp+20+28+40]
  59.     mov    edx,[esp+ 4+28+40]
  60.  
  61.     mov    ebp,[esp+16+28+40]
  62.  
  63. rowloop:
  64.     push    ebp
  65.     mov    ebp,[esp+12+32+40]
  66.     mov    eax,ebp
  67.     shl    eax,2
  68.     add    esi,eax
  69. colloop:
  70.     push    edx
  71.     push    ebp
  72.  
  73.     xor    eax,eax
  74.     xor    ebx,ebx
  75.     xor    ecx,ecx
  76.  
  77.     CONV_ADD    macro    p_source, p_mult
  78.  
  79.         mov    ebp,p_source    ;u    EDX = xRGB
  80.         mov    edx,ebp        ;u    EBP = xRGB
  81.         and    ebp,000000ffh    ;v    EBP = 000B
  82.         imul    ebp,p_mult    ;uv    EBP = 00bb
  83.         shr    edx,8        ;u    EDX = 0xRG
  84.         add    eax,ebp        ;v    add blues together
  85.         mov    ebp,edx        ;u    EBP = 0xRG
  86.         and    edx,0000ff00h    ;v    EDX = 00R0
  87.         shr    edx,8        ;u    EDX = 000R
  88.         and    ebp,000000ffh    ;v    EBP = 000G
  89.         imul    ebp,p_mult    ;uv    EBP = 00gg
  90.         imul    edx,p_mult    ;uv    EDX = 00rr
  91.         add    ebx,ebp        ;u
  92.         add    ecx,edx        ;v
  93.  
  94.         endm
  95.  
  96.     CONV_ADD [esi-4],[esp+24+12]
  97.     CONV_ADD [esi  ],[esp+28+12]
  98.     CONV_ADD [esi+4],[esp+32+12]
  99.     CONV_ADD [esi+edi-4],[esp+12+12]
  100.     CONV_ADD [esi+edi  ],[esp+16+12]
  101.     CONV_ADD [esi+edi+4],[esp+20+12]
  102.     CONV_ADD [esi+edi*2-4],[esp+0+12]
  103.     CONV_ADD [esi+edi*2  ],[esp+4+12]
  104.     CONV_ADD [esi+edi*2+4],[esp+8+12]
  105.  
  106.     mov    edx,[esp+36+12]
  107.     add    eax,edx
  108.     add    ebx,edx
  109.     add    ecx,edx
  110.  
  111.     test    eax,0ffff0000h
  112.     jz    nocarry1
  113.     sar    eax,31
  114.     xor    eax,-1
  115. nocarry1:
  116.  
  117.     test    ebx,0ffff0000h
  118.     jz    nocarry2
  119.     sar    ebx,31
  120.     xor    ebx,-1
  121. nocarry2:
  122.  
  123.     test    ecx,0ffff0000h
  124.     jz    nocarry3
  125.     sar    ecx,31
  126.     xor    ecx,-1
  127. nocarry3:
  128.  
  129.     shr    eax,8
  130.     and    ecx,0000ff00h
  131.     shl    ecx,8
  132.     and    eax,000000ffh
  133.     and    ebx,0000ff00h
  134.     add    eax,ecx
  135.     sub    esi,4
  136.     add    eax,ebx
  137.  
  138.     pop    ebp
  139.     pop    edx
  140.  
  141.     mov    [edx+ebp*4-4],eax
  142.     dec    ebp
  143.     jne    colloop
  144.  
  145.     pop    ebp
  146.  
  147.     add    esi,edi
  148.     add    edx,[esp+24+28+40]
  149.  
  150.     dec    ebp
  151.     jne    rowloop
  152.  
  153.     add    esp,40
  154.  
  155.     pop    eax
  156.     pop    ebx
  157.     pop    ecx
  158.     pop    edx
  159.     pop    esi
  160.     pop    edi
  161.     pop    ebp
  162.     ret
  163.  
  164.  
  165.     .code
  166.  
  167. ;asm_dynamic_convolute_run(
  168. ;    [esp+ 4] void *dst,
  169. ;    [esp+ 8] void *src,
  170. ;    [esp+12] ulong width,
  171. ;    [esp+16] ulong height,
  172. ;    [esp+20] ulong srcstride,
  173. ;    [esp+24] ulong dststride,
  174. ;    [esp+28] long *convol_matrix
  175. ;    [esp+32] void *dyna_code_ptr);
  176.  
  177. _asm_dynamic_convolute_run:
  178.     push    ebp
  179.     push    edi
  180.     push    esi
  181.     push    edx
  182.     push    ecx
  183.     push    ebx
  184.     push    eax
  185.  
  186.     sub    esp,4
  187.  
  188.     mov    esi,[esp+28+28+4]
  189.     mov    eax,[esi+36]
  190.     mov    [esp],eax
  191.  
  192.     mov    esi,[esp+ 8+28+4]
  193.     mov    edi,[esp+ 4+28+4]
  194.  
  195.     mov    ebp,[esp+16+28+4]
  196.  
  197. rowloop_dyna:
  198.     push    ebp
  199.     mov    ebp,[esp+12+32+4]
  200.     mov    eax,ebp
  201.     shl    eax,2
  202.     add    esi,eax
  203.  
  204.     call    dword ptr [esp+32+32+4]
  205.  
  206.  
  207.     pop    ebp
  208.  
  209.     add    esi,[esp+20+28+4]
  210.     add    edi,[esp+24+28+4]
  211.  
  212.     dec    ebp
  213.     jne    rowloop_dyna
  214.  
  215.     add    esp,4
  216.  
  217.     pop    eax
  218.     pop    ebx
  219.     pop    ecx
  220.     pop    edx
  221.     pop    esi
  222.     pop    edi
  223.     pop    ebp
  224.     ret
  225.  
  226. ;VC++4.0 is a broken compiler!!!!!!!!!!!!
  227.  
  228.     public    _asm_dynamic_convolute_codecopy
  229.  
  230. codetbl:
  231.     dd    _asm_dynamic_convolute_start_1
  232.     dd    _asm_dynamic_convolute_shift_1
  233.     dd    _asm_dynamic_convolute_end_1
  234.  
  235. _asm_dynamic_convolute_codecopy:
  236.     push    esi
  237.     push    edi
  238.     mov    esi,[esp+8+8]
  239.     mov    esi,[esi*4+codetbl]
  240.     mov    edi,[esp+4+8]
  241.     mov    ecx,[esi-4]
  242.     cld
  243.     rep    movsb
  244.     mov    eax,edi
  245.     pop    edi
  246.     pop    esi
  247.     ret
  248.  
  249.     dd    _asm_dynamic_convolute_start_2-_asm_dynamic_convolute_start_1
  250. _asm_dynamic_convolute_start_1:
  251.     push    edi
  252.     push    ebp
  253.  
  254.     xor    edx,edx
  255.     xor    edi,edi
  256.     xor    ebp,ebp
  257. _asm_dynamic_convolute_start_2:
  258.  
  259.     dd    _asm_dynamic_convolute_shift_2-_asm_dynamic_convolute_shift_1
  260. _asm_dynamic_convolute_shift_1:
  261.     sar    edi,8
  262.     mov    eax,[esp+12+4]
  263.     add    edx,eax
  264.     add    edi,eax
  265.     add    ebp,eax
  266. _asm_dynamic_convolute_shift_2:
  267.  
  268.     dd    _asm_dynamic_convolute_end_2-_asm_dynamic_convolute_end_1
  269. _asm_dynamic_convolute_end_1:
  270.     test    edx,0ffff0000h
  271.     jz    nocarry1d
  272.     sar    edx,31
  273.     xor    edx,-1
  274. nocarry1d:
  275.  
  276.     test    edi,0ffff0000h
  277.     jz    nocarry2d
  278.     sar    edi,31
  279.     xor    edi,-1
  280. nocarry2d:
  281.  
  282.     test    ebp,0ffff0000h
  283.     jz    nocarry3d
  284.     sar    ebp,31
  285.     xor    ebp,-1
  286. nocarry3d:
  287.  
  288.     shr    edx,8
  289.     and    ebp,0000ff00h
  290.     shl    ebp,8
  291.     and    edx,000000ffh
  292.     and    edi,0000ff00h
  293.     add    edx,ebp
  294.     sub    esi,4
  295.     add    edx,edi
  296.  
  297.     pop    ebp
  298.     pop    edi
  299.  
  300.     mov    [edi+ebp*4-4],edx        ;aggh!!! AGI!!!
  301.     dec    ebp
  302. _asm_dynamic_convolute_end_2:
  303.  
  304.     end
  305.